<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>React组件的API</title>
    <script src="https://cdn.staticfile.org/react/16.4.0/umd/react.development.js"></script>
    <script src="https://cdn.staticfile.org/react-dom/16.4.0/umd/react-dom.development.js"></script>
    <script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
</head>
<body>
    <div id="example"></div>
    <script type="text/babel">
       //1.设置状态：setState  setState(object nextState[, function callback])
       //nextState将要设置的新状态，该状态会和当前的state合并
       //可选参数，回调函数。该函数会在setState设置成功，且组件重新渲染后调用。
        class Counter extends React.Component{
            constructor(props){
                super(props);
                this.state = {
                  clickCount : 0
                };

                //事件绑定
                this.handleClick = this.handleClick.bind(this);

            }

            handleClick(){
                this.setState((state) => ({
                    clickCount : state.clickCount + 1
                }));
            }

            render(){
                return(
                    <div>
                        <h2>点击次数为：{this.state.clickCount}</h2>
                        <button onClick={this.handleClick}>点我啊</button>
                    </div>
                );
            }
        }

       ReactDOM.render(
           <Counter />,
           document.getElementById('example')
       );





        //2.替换状态：replaceState  replaceState(object nextState[, function callback])

        // 3.设置属性：setProps

        // 4.替换属性：replaceProps

        // 5.强制更新：forceUpdate forceUpdate([function callback]) 该函数会在组件render()方法调用后调用

        // 6.获取DOM节点：findDOMNode

        // 7.判断组件挂载状态：isMounted


    </script>

</body>
</html>